import React, { Component } from 'react';

import { history } from '../history';
import Welcome from "../components/welcome/Welcome";
import {loginWithGithub} from "../backend/auth";

export class Login extends Component{
  constructor(props) {
    super(props);
    this.login = this.login.bind(this);
  }
  login(){
    if (this.props.user.authenticated){

      return history.push('/');
    }
    loginWithGithub()
        .then(() => {
          history.push('/');
        })
  }

  render() {
    return (
        <div className="login">
          <div className="welcome-container">
            <Welcome />
          </div>
          <div className="providers">
            <button onClick={this.login}>
              <i className="fa fa-github" />用 Github 登陆
            </button>
          </div>
        </div>
    )
  }
}
